package com.tobeface.wechat.message;

import com.google.common.base.Joiner;
import com.tobeface.modules.lang.Function;
import com.tobeface.modules.lang.Langs;
import com.tobeface.modules.lang.Requires;
import com.tobeface.wechat.core.WeChatException;

import java.util.List;

/**
 * @author loudyn
 */
public class MultiDefaultMessageHandlerException extends WeChatException {

    /**
     * @param defaultMessageHandlers
     */
    public MultiDefaultMessageHandlerException(List<WeChatMessageHandler> defaultMessageHandlers) {
        super(buildExceptionMessage(defaultMessageHandlers));
    }

    private static String buildExceptionMessage(List<WeChatMessageHandler> defaultMessageHandlers) {
        Requires.notEmpty(defaultMessageHandlers);
        List<String> handleTypeNames = Langs.map(defaultMessageHandlers, new Function<WeChatMessageHandler, String>() {
            @Override
            public String apply(WeChatMessageHandler messageHandler) {
                return messageHandler.getClass().getName();
            }
        });
        return String.format("[%s] are all defined as defaultMessagehandler!", Joiner.on(",").join(handleTypeNames));
    }
}
